<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="crm.util.ParamUtil"%>
<%@page import="crm.model.Recepit"%>
<%@page import="crm.control.RecepitControl"%>
<%@page import="crm.model.Offer"%>
<%@page import="crm.control.DateControl"%>
<%@page import="crm.util.DateTime"%>
<%@page import="crm.control.EmployeesControl"%>
<%@page import="crm.control.OfferControl"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../resources/css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../resources/css/inner.css" type="text/css" media="screen" />

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>转入报价页面</title>
   <script type="text/javascript" src="../../../resources/js/WebCalendar.js"></script>
</head>
<body>
<%
            request.setCharacterEncoding("utf-8"); 
            int  recepitId= ParamUtil.getInt(request,"id");
            String action=ParamUtil.getString(request,"action","");
            Recepit re = RecepitControl.getRecepitById(recepitId);
            if(action==null||!action.equals("todo")){
%>
<br/>
您要提交转入报价审核的跟单是：<%=re.getTitle() %>
请您完善一下信息：
<form action="turn_to_offer.jsp?action=todo&&id=<%=recepitId %>" method="post">
<table>
<tr><td>报价主题</td><td><input type="text" name="theme" /></td></tr>
<tr><td>报价协商人</td><td><input type="text" name="manager" value="<%=EmployeesControl.getEmpolyeesById(re.getCurrent_person()).getName() %>"></td></tr>
<tr><td>报价金额</td><td><input type="text" name="offer_money" ><select name="danwei"><option value="0">元</option><option value="1">万元</option></select></td></tr>
<tr><td>报价日期 </td><td><input type="text" name="date"  maxlength="20"  onclick="SelectDate(this,'yyyy-MM-dd')" readonly  style="width:100px;cursor:pointer"/></td></tr>
<tr><td colspan='2'><input type="submit" class='button' value="提交">&nbsp;&nbsp;&nbsp;&nbsp;
<input class='button' type="reset" value="重写">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" class='button' value='返回' onclick='window.history.go(-1);'/>
</td></tr>
</table>
</form>
<%}else{
	        Offer of = new Offer();
	        of.setDate(ParamUtil.getString(request,"date",DateTime.DateTime()));
	        of.setManager(ParamUtil.getString(request,"manager",EmployeesControl.getEmpolyeesById(re.getCurrent_person()).getName())); //默认谈成合同人为对应跟单当前跟单人
	        of.setState("0");//默认状态为0
	        of.setRecepit_id(recepitId);
	        of.setDepartment("未填写");
	        of.setTheme(ParamUtil.getString(request,"theme","未填写"));
	        String off_money = ParamUtil.getString(request,"offer_money","0.0");  //先用String类型获取，避免出错
	        float money = Float.parseFloat(off_money);
	        if(ParamUtil.getString(request,"danwei").equals("1")){
	        	off_money =String.valueOf(money * 10000);
	        }
	        of.setOffer_money(off_money);
	        if(OfferControl.addOffer(of,3)){
	        	%>
	        	<script>
	        	alert("成功转入报价，报价审核中...")
	        	window.top.location.href="../offer/show_all_offers.jsp";
	        	</script>
	        	<%
	        }else{
	        	%>
	        	<script>
	        	alert("转入报价失败，请重试..");
	        	history.go(-1);
	        	</script>
	        	<%
	        }
	
} %>
</body>
</html>